/*
Fast Artificial Neural Network Library (fann)
Copyright (C) 2003-2012 Steffen Nissen (sn@leenissen.dk)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <stdio.h>

#include "fann.h"

int FANN_API test_callback(struct fann *ann, struct fann_train_data *train,
	unsigned int max_epochs, unsigned int epochs_between_reports,
	float desired_error, unsigned int epochs)
{
	printf("Epochs     %8d. MSE: %.5f. Desired-MSE: %.5f\n", epochs, fann_get_MSE(ann), desired_error);
	return 0;
}




int main(int argc, char *argv[])
{
	
	if (argc <2)
	{
		printf("0\nBadNumberOfParams");
		return 0;
	}
	
	const char* extIn = ".tenet";
	char* baseNetwork = argv[1];
	char* sourceIn = (char *)malloc(1 + strlen(extIn) + strlen(baseNetwork));
	strcpy(sourceIn, baseNetwork);
	strcat(sourceIn, extIn);
	
	struct fann *ann;
	ann = fann_create_from_file(sourceIn);

	int numInput = fann_get_num_input(ann);
	if (argc <numInput+1)
	{
		printf("0\Invalid number of inputs to network");
		return 0;
	}

	float* inputs = (fann_type *)malloc(numInput);

	for (int i = 0; i < numInput; i++)
	{
		inputs[i] = atof(argv[2 + i]);
		printf("%f", inputs[i]);
	}

	float* results = fann_run(ann, inputs);

	printf("1\n");

	int numOutputs = fann_get_num_output(ann);
	for (int j = 0; j < numOutputs; j++)
	{
		printf("%f", results[j]);
	}

	fann_destroy(ann);
	return 0;
}
